Skip to content

feat: Redirect rules (wildcard/pattern matching links)#3400

Draft
Suhaib3100 wants to merge 1 commit intodubinc:mainfrom
Suhaib3100:feat/redirect-rules
Draft

feat: Redirect rules (wildcard/pattern matching links)#3400
Suhaib3100 wants to merge 1 commit intodubinc:mainfrom
Suhaib3100:feat/redirect-rules

Conversation

@Suhaib3100
Copy link

Summary

Implements redirect rules (#529) - a highly requested feature that allows pattern-based URL matching for short links.

What it does

Instead of creating individual short links for every URL, users can now create a single redirect rule like:

  • /blog/* → redirects any /blog/hello-world, /blog/2024/post, etc.
  • /docs/:slug → redirects /docs/intro, /docs/api with captured params

Changes

Schema:

  • Added isRule (boolean) and rulePattern (string) fields to Link model
  • Added index on [domain, isRule] for efficient rule lookup

Middleware:

  • After exact link match fails, falls back to pattern matching
  • Rules cached per domain in Redis + LRU cache
  • Most specific pattern matches first (specificity scoring)

Analytics:

  • Uses existing alias_link_id field in Tinybird to track matched paths
  • Clicks aggregate under rule link, but you can see individual paths hit

API:

  • Rules are just links with isRule: true
  • Existing link endpoints work (POST /api/links with isRule + rulePattern)
  • Pro plan required for redirect rules

Pattern syntax

/blog/*           → matches /blog/anything, /blog/foo/bar
/docs/:slug       → matches /docs/intro, captures { slug: "intro" }
/api/:v/:endpoint → matches /api/v1/users, captures { v: "v1", endpoint: "users" }

Testing needed

  • Pattern matching edge cases
  • Cache invalidation when rules updated
  • Performance under load
  • UI for creating rules (not included - backend only)

Closes #529


Happy to adjust anything based on feedback!

@vercel
Copy link
Contributor

vercel bot commented Feb 1, 2026

@Suhaib3100 is attempting to deploy a commit to the Dub Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Feb 1, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

This adds support for redirect rules that use pattern matching to redirect
multiple URLs to a single destination. Closes dubinc#529.

Changes:
- Add isRule and rulePattern fields to Link schema
- Create rule-cache.ts for caching rules per domain
- Add match-rule.ts with pattern matching logic (wildcards, named params)
- Update middleware to fallback to rule matching when exact link not found
- Pass aliasLinkId to recordClick for analytics tracking
- Add validation in processLink for rule patterns
- Update Zod schemas and TypeScript types

Pattern syntax:
- Wildcards: /blog/* matches /blog/anything
- Named params: /docs/:slug matches /docs/intro (captures slug)
- Specificity-based matching (more specific patterns match first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Redirect rule

2 participants